import {
	$get,
	$post
} from '@/puigins/request.js';

export function autoLogin() {
	return new Promise((resolve, reject) => {
		$get('/user/autoLogin', null, {
			headers: {
				Authorization: window.localStorage.getItem("authorization")
			}
		}).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function updateName(name) {
	return new Promise((resolve, reject) => {
		$post('/user/updateName', {
			name
		}).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function updateGender(gender) {
	return new Promise((resolve, reject) => {
		$post('/user/updateGender', {
			gender
		}).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function logOut() {
	return new Promise((resolve, reject) => {
		$post('/user/logOut').then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}

export function qqLogin(openId, accessToken) {
	return new Promise((resolve, reject) => {
		$post('/user/qqLogin', {
			openId,
			accessToken
		}).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function userLogin(form) {
	return new Promise((resolve, reject) => {
		$post('/user/userLogin', form).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function requestYzm(form) {
	return new Promise((resolve, reject) => {
		$post('/user/requestYzm', form).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
export function registerUser(form) {
	return new Promise((resolve, reject) => {
		$post('/user/registerUser', form).then(({ data }) => {
			resolve(data)
		}).catch(reject)
	})
}
